package com.liuyk.activity;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.util.Pair;
import androidx.core.view.ViewCompat;

import com.liuyk.main.activity.R;
import com.liuyk.util.AnimationUtil;
import com.liuyk.widget.CircleImageView;

/**
 * DESC
 * <p>
 * Created by liuyakui on 2020/8/5.
 */
public class AnmiActivity extends BaseActivity implements View.OnClickListener {
    private ImageView stereoscopic_anim;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_anmi);
        findViewById(com.liuyk.main.activity.R.id.hcw).setOnClickListener(this);
        stereoscopic_anim = findViewById(com.liuyk.main.activity.R.id.stereoscopic_anim);
        stereoscopic_anim.setOnClickListener(this);
        stereoscopic_anim.post(new Runnable() {
            @Override
            public void run() {
                Log.i(TAG, "post");
                Log.i(TAG, "post_width: " + stereoscopic_anim.getWidth());
            }
        });

        new Thread(new Runnable() {
            @Override
            public void run() {
                Log.i(TAG, "postThread");
                Log.i(TAG, "postThread_width: " + stereoscopic_anim.getWidth());
            }
        }).start();
        Log.i(TAG, "postNext");
        Log.i(TAG, "postNext_width: " + stereoscopic_anim.getWidth());
        stereoscopic_anim.setOnClickListener(this);
        ViewCompat.setTransitionName(stereoscopic_anim, "stereoscopic_anim");


        CircleImageView circle_image = findViewById(com.liuyk.main.activity.R.id.circle_image);
        circle_image.setImageDrawable(getResources().getDrawable(com.liuyk.main.activity.R.drawable.animation_2));

        circle_sports();
    }

    private void circle_sports() {
        View circle_sports = findViewById(com.liuyk.main.activity.R.id.circle_sports);
        ObjectAnimator oa = ObjectAnimator.ofFloat(circle_sports, "progress", 0, 180);
        oa.setDuration(3000);
        oa.start();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case com.liuyk.main.activity.R.id.stereoscopic_anim:
//                stereoscopicAnim(v);
                //以旋转对象的中心点为旋转中心点，这里主要不要再onCreate方法中获取，因为视图初始绘制时，获取的宽高为0
                int centerX = v.getWidth() / 2;
                int centerY = v.getHeight() / 2;


                Pair<View, String> pair1 = new Pair<>(stereoscopic_anim, ViewCompat.getTransitionName(stereoscopic_anim));
                ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(this, pair1);
                ActivityCompat.startActivity(this, new Intent(this, ImageActivity.class), activityOptionsCompat.toBundle());
                break;

            case com.liuyk.main.activity.R.id.hcw:
                AnimationUtil.keyFrameScaleXY(v);
//                AnimationUtil.keyFrameWidth(v);
                break;
        }
    }
}
